package com.tongle.frs.common.util;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class ObjectSerialUtils
{
  public static byte[] objectToBytes(Object obj)
    throws Exception
  {
    ByteArrayOutputStream bo = new ByteArrayOutputStream();
    ObjectOutputStream oo = new ObjectOutputStream(bo);
    oo.writeObject(obj);
    byte[] bytes = bo.toByteArray();
    bo.close();
    oo.close();
    return bytes;
  }

  public static Object bytesToObject(byte[] bytes)
    throws Exception
  {
    ByteArrayInputStream in = new ByteArrayInputStream(bytes);
    ObjectInputStream sIn = new ObjectInputStream(in);
    return sIn.readObject();
  }
}